import {UserActions} from './user';

const initialState = {
  MerchantCode: '',
  PaymentId: '',
  RefNo: '',
  Amount: '',
  Currency: '',
  ProdDesc: '',
  UserName: '',
  UserEmail: '',
  UserContact: '',
  SignatureType: '',
  Signature: '',
  ResponseURL: '',
  BackendURL: '',
};

export const CheckoutActions = {
  CHECKOUT_FORM_UPDATE: 'checkout_form_update',
  CHECKOUT_FORM_RESET: 'checkout_form_reset',
};

export function updateCheckoutForm(payload) {
  return {
    type: CheckoutActions.CHECKOUT_FORM_UPDATE,
    payload,
  };
}

export function resetCheckoutForm() {
  return {
    type: CheckoutActions.CHECKOUT_FORM_RESET,
  };
}

export default function checkoutForm(state = initialState, action) {
  switch (action.type) {
    case CheckoutActions.CHECKOUT_FORM_UPDATE:
      return {...state, ...action.payload};
    case CheckoutActions.CHECKOUT_FORM_RESET:
      return {};
    case UserActions.USER_SIGN_OUT:
      return {
        MerchantCode: '',
        PaymentId: '',
        RefNo: '',
        Amount: '',
        Currency: '',
        ProdDesc: '',
        UserName: '',
        UserEmail: '',
        UserContact: '',
        SignatureType: '',
        Signature: '',
        ResponseURL: '',
        BackendURL: '',
      };
    default:
      return state;
  }
}
